package com.yywq.controller;

import com.yywq.error.BusinessException;
import com.yywq.error.EnumBusinessError;
import com.yywq.pojo.model.GoodsInfo;
import com.yywq.response.CommonReturnType;
import com.yywq.service.impl.GoodsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 吴磊
 * @program: yywq_parent
 * @create: 2021-04-13 14:16
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsServiceImpl goodsService;


    /**
     * 获取商品详情
     *
     * @param goodsId
     * @return
     * @throws BusinessException
     */
    @RequestMapping(value = "/getGoodsInfo", method = RequestMethod.GET)
    private CommonReturnType getGoodsInfo(@RequestParam("goodsId") String goodsId) throws BusinessException {
        if (StringUtils.isEmpty(goodsId)) {
            throw new BusinessException(EnumBusinessError.PARAMETER_INVALID_ERROR);
        }
        GoodsInfo goodsInfo = goodsService.getGoodsInfo(goodsId);
        return CommonReturnType.create(goodsInfo);
    }


}
